#include <stdio.h>
#include <stdlib.h>

int check(int array[], int use[], int length, int curIndex, int laseOne)
{
	if( curIndex >= length )
		return 0;

	int useLength;
	if( laseOne < array[curIndex] )
		useLength = use[curIndex];
	else
		useLength = 0;
	
	int unUseLength = check( array, use, length, curIndex+1, laseOne );

	return useLength>unUseLength ? useLength : unUseLength;
}

int mainFunc(int a[], int use[], int unUse[], int length)
{
	use[length-1] = 1;
	unUse[length-1] = 0;

	for(  int i=length-2; i>=0; i-- )
	{
		use[i] = 1 + check(a, use, length, i+1, a[i] );
		unUse[i] = unUse[i+1]>use[i+1] ? unUse[i+1] : use[i+1];
	}

	return use[0]>unUse[0] ? use[0] : unUse[0];
}


int main()
{
	int n;
	scanf("%d", &n);
	
	int number, result;
	int *array = new int[3000];
	int *inUseArray = new int[3000];
	int *unUseArray = new int[3000];

	for(int i=0; i<n; i++)
	{
		scanf("%d", &number);
		for(int j=0; j<number;j++)
			scanf("%d", array+j);
		
		result = mainFunc( array, inUseArray, unUseArray, number );
		printf( "%d\n", result );
	}

	return 0;
}
